package user

import (
	"context"

	"go-zero_try/mall/order/api/internal/svc"
	"go-zero_try/mall/order/api/internal/types"
	"go-zero_try/mall/order/rpc/pb/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserDeleteLogic {
	return &UserDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserDeleteLogic) UserDelete(req *types.DeleteAndQueryReq) (resp *types.DeleteAndQueryReps, err error) {
	userResp, err := l.svcCtx.UserClient.Del(l.ctx, &pb.DelAndQryReq{
		UID: req.UID,
	})

	if err != nil {
		return nil, err
	}

	return &types.DeleteAndQueryReps{
		Msg:  userResp.Msg,
		UID:  userResp.UID,
		Name: userResp.Name,
		Age:  userResp.Age,
	}, nil
}
